package com.example.myapplication;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;

public class ThingAdapter extends ArrayAdapter<Thing> {
    public ThingAdapter(@NonNull Context context, int resource, @NonNull List<Thing> objects) {
        super(context, resource, objects);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Thing thing=getItem(position);
        View view= LayoutInflater.from(getContext()).inflate(R.layout.thinglabel,parent,false);
        ImageView image=view.findViewById(R.id.thingimage);
        TextView id=view.findViewById(R.id.thingid);
        TextView name=view.findViewById(R.id.thingname);
        TextView tags=view.findViewById(R.id.thingtags);

        id.setText(String.valueOf(thing.getId()));//注意要做类型转换;
        image.setImageBitmap(BitmapUtils.loadBitmap(thing.getImagePath()));
        name.setText(thing.getName());
        tags.setText(thing.getEditDate());
        Log.d("输出", "getView: 加载数据项"+position);
        return view;
    }
}
